/*
 * CWeapon.java
 *
 * Copyright (c) 2009 Giles Millward (Manigra). All rights reserved.
 *
 * This file is part of JRogueDPS.
 *
 * JRogueDPS is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * JRogueDPS is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with JRogueDPS.  If not, see <http://www.gnu.org/licenses/>.
 */

package dpssystem;

import dpsstats.CDamageStats;
import dpsstats.CProcStats;
import geardatabase.CProcItem;

/**
 *
 * @author Mani
 */
public class CWeapon {

    public enum WeaponType {DAGGER, SWORD, MACE, FIST, AXE};

    CWeapon(String p_name, double p_minDamage, double p_maxDamage, double p_weaponSpeed,
                double p_handModifier, CPoison.PoisonType p_poisonType, WeaponType p_weaponType,
                CDamageStats p_autoAttackStats,
                CDamageStats p_poisonStats,
                boolean p_mainHand,
                CProcItem p_procItem,
                CSim p_sim)
    {
        m_mainHand = p_mainHand;
        m_name = p_name;
        m_minDamage = p_minDamage;
        m_maxDamage = p_maxDamage;
        m_avgDamage = 0.5 * (double) (m_minDamage + m_maxDamage);
        m_weaponSpeed = p_weaponSpeed;
        m_handModifier = p_handModifier;
        m_weaponDPS = m_avgDamage / p_weaponSpeed;
        m_weaponType = p_weaponType;
        m_autoAttackStats = p_autoAttackStats;

        if (m_weaponType == WeaponType.DAGGER) {
            m_normalization = 1.7;
            m_isDagger = true;
        } else {
            m_normalization = 2.4;
        }

        if (m_weaponType == WeaponType.FIST)
        {
            m_isFist = true;
        } else if (m_weaponType == WeaponType.SWORD)
        {
            m_isSword = true;
        } else if (m_weaponType == WeaponType.AXE)
        {
            m_isAxe = true;
        } else if (m_weaponType == WeaponType.MACE)
        {
            m_isMace = true;
        }


        // Setup Poison for this weapon
        if (p_poisonType == CPoison.PoisonType.INSTANT)
        {
            m_poison = new CPoisonInstant(this, p_poisonStats, p_sim);
        } else if (p_poisonType == CPoison.PoisonType.NONE)
        {
            m_poison = new CPoisonNone(this, p_poisonStats, p_sim);
        } else if (p_poisonType == CPoison.PoisonType.WOUND)
        {
            m_poison = new CPoisonWound(this, p_poisonStats, p_sim);
        } else if (p_poisonType == CPoison.PoisonType.DEADLY)
        {
            m_poison = new CPoisonDeadly(this, p_poisonStats, p_sim);
        }

        setupProc(p_procItem, p_sim);
    }

    public void showStats()
    {
        System.out.println(m_name + " minDamage [" + m_minDamage + "] maxDamge [" + m_maxDamage + "] avgDamage [" +
                m_avgDamage + "] weaponSpeed [" + m_weaponSpeed + "] handModifier [" + m_handModifier + "] weaponDPS [" + m_weaponDPS + "]");
    }

    public void setOtherWeapon(CWeapon p_weapon)
    {
        m_otherHandWeapon = p_weapon;
    }
    
    private void setupProc(
                CProcItem p_procItem,
                CSim p_sim
                )
    {
        if (p_procItem == null)
        {
            m_enchantId = 0;
            return;
        }

        m_enchantId = p_procItem.m_id;
        CProcStats l_procStats = new CProcStats(p_procItem.m_name);
        this.m_enchantProc = new CProcGeneric(p_procItem, l_procStats, this);
        p_sim.m_stats.m_procStats.add(l_procStats);
    }
    
    public double  m_minDamage;
    public double  m_maxDamage;
    public double  m_avgDamage;
    public double m_weaponSpeed;
    public double m_handModifier;
    public double m_weaponDPS;
    public double m_normalization;
    public boolean m_mainHand;
    public WeaponType m_weaponType;
    public CDamageStats m_autoAttackStats;
    public int     m_enchantId;
    public boolean m_isFist = false;
    public boolean m_isDagger = false;
    public boolean m_isMace = false;
    public boolean m_isSword = false;
    public boolean m_isAxe = false;

    // Poison that is applied on this weapon
    public CPoison m_poison;

    // If there is an enchant on this weapon and its a funky
    // proc then this gets setup here
    public CProc m_enchantProc;

    // pointer to the other weapon
    public CWeapon m_otherHandWeapon;
    String m_name;
}
